//
//  WorksDetailViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/3/9.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "WorksDetailViewController.h"


@interface WorksDetailViewController ()

@end

@implementation WorksDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的作品";
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW , kScreenW/2 + 20 +30)];
    headView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableHeaderView = headView;
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW/4, 20, kScreenW/2, kScreenW/2)];
    [imageView sd_setImageWithURL:[NSURL URLWithString:self.worksDetailInfo.img] placeholderImage:KRECOMMENDLISTDEFAULT];
    imageView.clipsToBounds = YES;
    imageView.layer.borderWidth = 0.5;
    imageView.layer.borderColor = KBORDERCOLOR.CGColor;
    [headView addSubview:imageView];
    
    UIView *sepView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(imageView.frame) + 20, kScreenW , 10)];
    sepView.backgroundColor = KBACKGROUNDCOLOR;
    [headView addSubview:sepView];
}
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView{
    if (strIsEmpty(self.worksDetailInfo.answer1)) {
        return 2;
    }
    return 4;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell3";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    NSMutableArray *array = [[NSMutableArray alloc]init];
    if (strIsEmpty(self.worksDetailInfo.answer1)) {
        array = [NSMutableArray arrayWithObjects:self.worksDetailInfo.answer3,self.worksDetailInfo.answer4, nil];
    }else{
        array = [NSMutableArray arrayWithObjects:self.worksDetailInfo.answer1,self.worksDetailInfo.answer2,self.worksDetailInfo.answer3,self.worksDetailInfo.answer4, nil];
    }
    cell.textLabel.text = array[indexPath.section];
    cell.textLabel.font = [UIFont systemFontOfSize:16];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSMutableArray *array = [[NSMutableArray alloc]init];
    if (strIsEmpty(self.worksDetailInfo.answer1)) {
        array = [NSMutableArray arrayWithObjects:self.worksDetailInfo.answer3,self.worksDetailInfo.answer4, nil];
    }else{
        array = [NSMutableArray arrayWithObjects:self.worksDetailInfo.answer1,self.worksDetailInfo.answer2,self.worksDetailInfo.answer3,self.worksDetailInfo.answer4, nil];
    }
    return [Global getSizeOfString:array[indexPath.section] maxWidth:kScreenW - 20 maxHeight:MAXFLOAT withFontSize:16].height + 20;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    NSMutableArray *textArray = [[NSMutableArray alloc]init];
    if (strIsEmpty(self.worksDetailInfo.answer1)) {
        textArray = [NSMutableArray arrayWithObjects:@"请给你的作品取个名字？",@"你的作品让你联想到什么？", nil];
    }else{
        textArray = [NSMutableArray arrayWithObjects:@"你现在的心情如何？",@"今天什么事让你印象深刻？",@"请给你的作品取个名字？",@"你的作品让你联想到什么？", nil];
    }
    
     UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 44)];
     view.backgroundColor = [UIColor whiteColor];
     
     UILabel *sepLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 4, 20)];
     sepLabel.backgroundColor = KBACKNAVIGATIONCOLOR;
     [view addSubview:sepLabel];
     
     UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, kScreenW - 20, 30)];
     nameLabel.textAlignment = NSTextAlignmentLeft;
     nameLabel.font = [UIFont systemFontOfSize:16];
     nameLabel.textColor = KTEXTMAINCOLOR;
     nameLabel.text = textArray[section];
     [view addSubview:nameLabel];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 44;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 10)];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
